﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 客户端
{
    public partial class login : Form
    {
        public static string constr = "Data Source=DESKTOP-VI5F5HT;Initial Catalog = KHDGDB; Integrated Security = True; Connect Timeout = 15; Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
        public static Mainform mainform;
        public Register register;
        public login()
        {
            InitializeComponent();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            购物车.account=购买记录.account=个人信息.account=pay.Caccount=发票.account=选购界面.Caccount=修改密码.id = tb_usr.Text.Trim();
            string uername = tb_usr.Text.Trim();
            string pwd = tb_pwd.Text.Trim();
            SqlConnection con = new SqlConnection(constr);            // 建立SqlConnection对象
            con.Open();            // 打开连接
            // 指定SQL语句
            SqlCommand com = new SqlCommand("select Caccount,Cpassword from Customer where Caccount='" + uername + "' and Cpassword='" + pwd + "'", con);
            // 建立SqlDataAdapter和DataSet对象
            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();
            int n = da.Fill(ds, "register");
            if (n != 0)
            {
                mainform = new Mainform();
                mainform.Show();
                this.Hide();
            }
            else if (tb_usr.Text == string.Empty || tb_pwd.Text == string.Empty)
            {
                MessageBox.Show("信息不完整！", "提示");
                return;
            }
            else
            {
                MessageBox.Show("账号或密码错误，请重新输入！", "提示");
                tb_usr.Text = "";
                tb_pwd.Text = "";
            }
        }

        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lb_register_Click(object sender, EventArgs e)
        {
            register = new Register();
            register.Show();
        }
    }
}
